import pytest
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from mixed_access_control import MixedAccessControl

@pytest.yield_fixture(scope='function')
def app():
    """An application for the tests."""
    _app = Flask(__name__)
    _app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
    _app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    _app.secret_key = b'_5#y2L"F4Q8z\n\xec]/'

    _app.db = SQLAlchemy(_app)
    _app.mixed_ac = MixedAccessControl(_app, _app.db)

    ctx = _app.test_request_context()
    ctx.push()

    yield _app

    ctx.pop()

